package edu.gdkm.dao;

import edu.gdkm.pojo.Course;
import edu.gdkm.pojo.Student;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface ICourseDao {
    @Select("select * from t_course where cid=#{id}")
    @Results({
            @Result(
                    property = "teacher",
                    column = "tid",
                    one=@One(select = "edu.gdkm.dao.ITeacherDao.queryTeacherById")
            )
    })
    public Course queryCourseById(Integer id);  //根据cid查找课程和老师

    @Select("select * from t_course")
    @Results({
            @Result(
                    property = "teacher",
                    column = "tid",
                    one=@One(select = "edu.gdkm.dao.ITeacherDao.queryTeacherById")
            )
    })
    public List<Course> queryCourse();  //显示所有课程和对应的老师

    @Insert("insert into t_course values(null,#{coursename},#{teacher.tid})")
    public Integer insertCourse(Course course);    //教师新增课程

    @Select("select * from t_course where tid=#{tid}")
    public List<Course> queryCourseByCid(Integer tid);  //根据tid查找课程

    @Select("select * from t_course where cid=#{cid}")
    @Results({
            @Result(property = "cid",column = "cid"),
            @Result(
                    property = "studentList",
                    column = "cid",
                    many=@Many(select = "edu.gdkm.dao.IStudentDao.queryStudentsByCid")
            )
    })
    public Course queryStudentsByCid(Integer cid);    //根据cid查找学生
}
